/**
 *
 * 建造工具
 * @author 
 *
 */
class BuildTool extends egret.Sprite {
    
    private bm: egret.Bitmap;
    private icon: BuildIcon;
    private gold: number;
    protected objTouch: any;
    
    //根据当前选中对象类型生成建造工具
	public constructor(obj:any,gold:number) {
        super();
        this.cacheAsBitmap = true;

        this.scaleX = this.scaleY = 0.5;
        this.alpha = 0;
        //工具圆圈
        this.bm = Utils.createBitmapByName("yuan");
        this.addChild(this.bm);
        this.anchorOffsetX = this.width / 2;
        this.anchorOffsetY = this.height / 2;
        
        //当前关卡拥有金钱
        this.gold = gold;
        //生成建造工具ICON
        this.objTouch = obj;
        this.createTools(obj);
        
        //展开动画
        TweenMax.to(this,0.1,{ alpha: 1,scaleX: 1,scaleY: 1});
	}
	
	/**根据当前选中对象类型生成建造工具*/
	private createTools(obj:any){
    	
        if(obj.nameInfo=="s01") {
            this.addIcon("s11",36,-14);
            this.addIcon("SellTower",43,98)
        } else if(obj.nameInfo == "s02") {
            this.addIcon("s12",36,-14);
            this.addIcon("SellTower",43,98);
        } else if(obj.nameInfo == "s03") {
            this.addIcon("LockTower",36,-14);
            this.addIcon("SellTower",43,98);;
        } else if(obj.nameInfo == "s04") {
            this.addIcon("s14",36,-14);
            this.addIcon("SellTower",43,98);
        } else if(obj.nameInfo == "s05") {
            this.addIcon("LockTower",36,-14);
            this.addIcon("SellTower",43,98);;
        } else if(obj.nameInfo == "s06") {
            this.addIcon("LockTower",36,-14);
            this.addIcon("SellTower",43,98);;
        } else if(obj.nameInfo == "s11") {
            this.addIcon("LockTower",36,-14);
            this.addIcon("SellTower",43,98);;
        } else if(obj.nameInfo == "s12") {
            this.addIcon("LockTower",36,-14);
            this.addIcon("SellTower",43,98);;
        } else if(obj.nameInfo == "s14") {
            this.addIcon("LockTower",36,-14);
            this.addIcon("SellTower",43,98);;
        }else if(obj.nameInfo == "myLord") {
            this.addIcon("gold",36,-14);
            this.addIcon("tower",-14,43);
            this.addIcon("arrow",85,43);
        }else{//塔--------------------------------------------------------03_1  03_2
            this.addIcon("SellTower",43,98);
        }
        
	}
	
	/**建造一个icon*/
	private addIcon(type:string,x:number,y:number){
        this.icon = new BuildIcon(type,this.gold,this.objTouch);
        this.icon.x = x;
        this.icon.y = y;
        this.icon.addEventListener(egret.TouchEvent.TOUCH_BEGIN,this.iconClickHandle,this);
        this.addChild(this.icon);
	}
	
	/**建造icon点击事件*/
	private iconClickHandle(e:egret.TouchEvent){
        var className = e.currentTarget.className;
        var price = e.currentTarget.price;
        if(e.currentTarget.is == false){
            e.currentTarget.is = true;
            return;
        }
        if(this.gold >= price)
        this.dispatchEvent(new ToolEvent(ToolEvent.BUILD_START,className,price));
	}
	
	/**隐藏工具*/
	public hide(){
        var that = this;

        TweenMax.to(that,0.1,{ alpha: 0,scaleX: 0.5,scaleY: 0.5,onComplete: function() { 
            if(that.parent!=null){
                that.parent.removeChild(that);
            }
            }});
	}
}
